/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.swing.JOptionPane;
import model.Tramitacao;
import util.jpaUtil;

/**
 *
 * @author calandreli
 */
public class TramitacaoDAO extends JPAHibernateDAO {

    @Override
    public Class obterClasse() {
        return Tramitacao.class;
    }

    public List<Tramitacao> pesquisaTramitacao(int cod) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("select t from Tramitacao t where t.processo.id_Processo =:codProc");
        query.setParameter("codProc", cod);
        return query.getResultList();
    }

    public List<Tramitacao> pesquisaTramitacaoNumero(String cod) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("select t from Tramitacao t where t.processo.numeroProcesso =:codProc");
        query.setParameter("codProc", cod);
        return query.getResultList();
    }

    public List<Tramitacao> pesquisaTramitacaoSetor(String sigla) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("select t from Tramitacao t where t.setorReceb in (Select s.id_setor from Setor s where s.sigla like :sigla)");
        //Query query = em.createQuery("select t from Tramitacao t, Setor s where t.setorReceb.id_setor = s.id_setor AND t.setorReceb.sigla =:sigla");
        //Query query = em.createQuery("select t from Tramitacao t where t.setorReceb =:id");
        //Query query = em.createQuery("");
        query.setParameter("sigla", sigla);
        return query.getResultList();
    }

    public List<Tramitacao> pesquisaTramitacaoRecebida(boolean op) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("select t from Tramitacao t where t.recebido =:op");
        //Query query = em.createQuery("select t from Tramitacao t, Setor s where t.setorReceb.id_setor = s.id_setor AND t.setorReceb.sigla =:sigla");
        //Query query = em.createQuery("select t from Tramitacao t where t.setorReceb =:id");
        //Query query = em.createQuery("");
        query.setParameter("op", op);
        return query.getResultList();
    }

//    //Megazorde kk
//    public List<Tramitacao> pesquisaTramitacaoSetor2(String sigla, boolean op) {
//        EntityManager em = jpaUtil.getEntityManager();
//        Query query = em.createQuery("select t from Tramitacao t where t.setorReceb in (Select s.id_setor from Setor s where s.sigla like :sigla and t.recebido =:op )");
//        //Query query = em.createQuery("select t from Tramitacao t, Setor s where t.setorReceb.id_setor = s.id_setor AND t.setorReceb.sigla =:sigla");
//        //Query query = em.createQuery("select t from Tramitacao t where t.setorReceb =:id");
//        //Query query = em.createQuery("");
//        query.setParameter("sigla", sigla);
//        query.setParameter("op", op);
//
//        return query.getResultList();
//    }
}
